import saveData from "../utils/save";
import onload from "../utils/onload";
import getTime from "../utils/getTime";
export function timing() {
  // 刚开始页面内容为空，等页面渲染完成，再去做判断
  onload(function () {
    setTimeout(() => {
      let t = performance.timing;
      let FP = performance.getEntriesByName("first-paint")[0];
      let FCP = performance.getEntriesByName("first-contentful-paint")[0];
      let time = getTime();
      // 发送时间指标
      let log = {
        kind: "performance", // 用户体验指标
        type: "time", // 统计每个阶段的时间
        time: time, // 当前时间
        FP: FP ? FP.startTime : 0, // 首次渲染时间
        FCP: FCP ? FCP.startTime : 0,// 首次可见时间
        DNSTime: t.domainLookupEnd - t.domainLookupStart, // DNS查询耗时
        DOMReady: t.domContentLoadedEventEnd - t.fetchStart// DOM Ready耗时
      };
      console.log(log);
      saveData(log, "performance");
    }, 3000);
  });
}
